#ifndef _SRC_NET_EVENT_LOOP_THREAD_H_
#define _SRC_NET_EVENT_LOOP_THREAD_H_

#include <condition_variable>
#include <functional>
#include <mutex>
#include <string>
#include <thread>

#include "src/base/utils.h"

namespace fio66::net {
class EventLoop;

class EventLoopThread {
 public:
  DISALLOW_COPY_AND_ASSIGN_LOG(EventLoopThread)
  typedef std::function<void(EventLoop*)> ThreadInitCallback;

  EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
                  const std::string& name = "");
  ~EventLoopThread();
  EventLoop* StartLoop();

 private:
  void ThreadFunc();

  std::string name_;
  EventLoop* loop_;
  bool exiting_;
  std::jthread thread_;
  std::mutex mutex_;
  std::condition_variable cond_;
  ThreadInitCallback callback_;
};

}  // namespace fio66::net

#endif  // _SRC_NET_EVENT_LOOP_THREAD_H_
